﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics.Contracts;

namespace DataStructure.Interview
{
    public class Question3
    {
        public static char[] RemoveDuplicated(char[] str)
        {
            
            if (str == null)
                throw new ArgumentNullException("str");

            if (str.Length < 2)
                return str;

            int tail = 1;
            for (int i = 0; i < str.Length; i++)
            {
                int j = 0;
                for (j = 0; j < tail; j++)
                {
                    if (str[i] == str[j])
                        break;
                }

                if (j == tail)
                {
                    str[tail] = str[i];
                    tail++;
                }
            }
            char[] result = new char[tail];
            Array.Copy(str, result, result.Length);
            return result;
        }



    }
}
